#!/bin/sh

TMP="/tmp/$(date +"%Y-%m-%d_%H:%M:%S").png"
DIR="$HOME/Pictures/$(date +"%Y-%m-%d_%H:%M:%S").png"

if [ "$1" = "-s" ] && [ "$2" = "-r" ]; then
	import -quality 100 -window root $DIR
	notify-send -u low -i "$DIR" "Print" "Saved in $DIR"
fi

if [ "$1" = "-s" ] && [ "$2" = "-a" ]; then
	import -quality 100 $DIR
	notify-send -u low -i "$DIR" "Print" "Area saved in $DIR"
fi

if [ "$1" = "-c" ] && [ "$2" = "-r" ]; then
	import -quality 100 -window root $TMP
	xclip -selection c -t image/png $TMP
	notify-send -u low -i "$TMP" "Print" "Copied to clipboard"
fi

if [ "$1" = "-c" ] && [ "$2" = "-a" ]; then
	import -quality 100 $TMP
	xclip -selection c -t image/png $TMP
	notify-send -u low -i "$TMP" "Print" "Area copied to clipboard"
fi

if [ "$1" = "-u" ] && [ "$2" = "-r" ]; then
	import -quality 100 -window root $TMP
	xclip -selection c -i <<< $(curl -F file=@$TMP http://0x0.st)
	notify-send -u low -i "$TMP" "Print" "Uploaded and url copied"
fi

if [ "$1" = "-u" ] && [ "$2" = "-a" ]; then
	import -quality 100 $TMP
	xclip -selection c -i <<< $(curl -F file=@$TMP http://0x0.st)
	notify-send -u low -i "$TMP" "Print" "Area uploaded and url copied"
fi
